<?php
if (isset($_SESSION['player_id'])) {
$query = "SELECT `role_id`, `team_id`
				FROM `players`
				WHERE `id`='{$_SESSION['player_id']}'
				LIMIT 1";
	$sql = mysql_query($query) or die(mysql_error());
	if (mysql_num_rows($sql)==1)
	{
	   $cap=mysql_fetch_assoc($sql);
       if ($cap['role_id']==1 && $cap['team_id']!=''){

if (isset($_GET['action']) &&  $_GET['action']=="add" && isset($_GET['id']) && is_numeric($_GET['id'])){
	mysql_query("UPDATE players
							SET
							`team_id`={$cap['team_id']}
							WHERE `id`={$_GET['id']}") or die(mysql_error());
	mysql_query("DELETE FROM invite							
							WHERE `player_id`={$_GET['id']}") or die(mysql_error());
	echo "Вы приняли нового члена команды!";
}
	else{
if (isset($_GET['action']) &&  $_GET['action']=="refuse" && isset($_GET['id']) && is_numeric($_GET['id'])){

	mysql_query("DELETE FROM invite							
							WHERE `player_id`={$_GET['id']}") or die(mysql_error());

	echo "Вы отказали на вступление в команду!";
}
else{
echo '<h3>Список заявок в команду:</h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 <tr bgcolor="#000000"> 
  <td width="100%">
  <table border="0" width="100%">
    <tr bgcolor="#222222"> 
	<td valign="bottom" colspan="2" > 
	№
	</td>
	<td valign="bottom" colspan="2" > 
	Login
	</td>
	<td valign="bottom" colspan="2" > 
	Имя
	</td>
	<td valign="bottom" colspan="2" > 
	Фамилия
	</td>
	</td>
	<td valign="bottom" colspan="2" > 
	Роль
	</td>
	<td valign="bottom" colspan="2" > 
	Принять
	</td>
	</tr>';
	

        $sqlresult = mysql_query("SELECT  `player_id`, `login`, `fname`, `sname`, `player_id`, `role`
         FROM invite, players, roles WHERE invite.team_id={$cap['team_id']} and `player_id`=players.id and players.role_id=roles.id;") or die (mysql_error());
		
        $numrows = mysql_num_rows($sqlresult);
        for ($i=1;$i<=$numrows;$i++){
        $sqlteam = mysql_fetch_assoc($sqlresult);
        echo "<tr bgcolor=\"#333333\"> 
            <td valign=\"bottom\" colspan=\"2\" >{$i}</td>
            <td valign=\"bottom\" colspan=\"2\" >{$sqlteam['login']}</td>
            <td valign=\"bottom\" colspan=\"2\" >{$sqlteam['fname']}</td>
            <td valign=\"bottom\" colspan=\"2\" >{$sqlteam['sname']}</td>
            <td valign=\"bottom\" colspan=\"2\" >{$sqlteam['role']}</td>
			<td valign=\"bottom\" colspan=\"2\" >
			<a href=\"index.php?section=team&mode=invites&action=add&id={$sqlteam['player_id']}\">[Да]</a> |
			<a href=\"index.php?section=team&mode=invites&action=refuse&id={$sqlteam['player_id']}\">[Нет]</a></td></tr>";

}

        print '</table>	</td>	</tr>	</table>';
}
}
}
}
}


else
{
	print 'Время вашей сессии истекло!';
	}
?>